{% extends "admin_base.html" %}

{% block content %}
<div class="card border-0 shadow-sm">
    <div class="card-header bg-white border-0 py-3 d-flex justify-content-between align-items-center">
        <h5 class="mb-0"><i class="bi bi-people me-2"></i> 客户管理</h5>
        <div>
            <a href="{{ url_for('add_customer') }}" class="btn btn-primary">
                <i class="bi bi-plus-circle me-1"></i> 添加客户
            </a>
        </div>
    </div>
    <div class="card-body">
        <!-- 搜索表单 -->
        <form class="mb-4" method="GET" action="{{ url_for('manage_customers') }}">
            <div class="row g-3">
                <div class="col-md-6">
                    <div class="input-group">
                        <input type="text" class="form-control" name="search" 
                               value="{{ search_term }}" placeholder="输入搜索内容">
                        <button class="btn btn-primary" type="submit">
                            <i class="bi bi-search"></i> 搜索
                        </button>
                    </div>
                </div>
                                <div class="col-md-3">
                    <label for="searchType">搜索类型</label>
                    <select class="form-select" id="searchType" name="type">
                        <option value="name" {% if search_type == 'name' %}selected{% endif %}>按姓名</option>
                        <option value="id" {% if search_type == 'id' %}selected{% endif %}>按ID</option>
                        <option value="phone" {% if search_type == 'phone' %}selected{% endif %}>按电话</option>
                    </select>
                </div>

                <div class="col-md-3">
                    <a href="{{ url_for('manage_customers') }}" class="btn btn-outline-secondary">
                        <i class="bi bi-arrow-counterclockwise"></i> 重置
                    </a>
                </div>
            </div>
        </form>
        
        <!-- 客户列表 -->
        <div class="table-responsive">
            <table class="table table-hover align-middle">
                <thead class="table-light">
                    <tr>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>身份证号</th>
                        <th>电话</th>
                        <th>地址</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for customer in customers %}
                    <tr>
                        <td>{{ customer.id }}</td>
                        <td>{{ customer.name }}</td>
                        <td>{{ customer.pid }}</td>
                        <td>{{ customer.phone }}</td>
                        <td>{{ customer.address }}</td>
                        <td>
                            <div class="btn-group">
                                <a href="{{ url_for('edit_customer', customer_id=customer.id) }}" 
                                   class="btn btn-sm btn-outline-primary">
                                    <i class="bi bi-pencil"></i> 编辑
                                </a>
                                <form method="POST" action="{{ url_for('delete_customer', customer_id=customer.id) }}" 
                                      class="d-inline" onsubmit="return confirm('确定要删除该客户吗？');">
                                    <button type="submit" class="btn btn-sm btn-outline-danger">
                                        <i class="bi bi-trash"></i> 删除
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="6" class="text-center py-4">没有找到客户记录</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}